#pragma once
#include "HashTable.h"
using namespace OPEN_HASH;

namespace ztx
{
	template<class K, class V, class Hash = OPEN_HASH::_Hash<K>>
	class unordered_map
	{
	private:
		struct MapOfValue
		{
			const K& operator()(const pair<K, V>& pair)
			{
				return pair.first;
			}
		};


		HashTable<K, pair<K, V>, MapOfValue, Hash> _ht;
	public:
		typedef typename HashTable<K, pair<K,V>, MapOfValue, Hash>::iterator iterator;

		pair<iterator, bool > insert(const pair<K, V>& kv)
		{
			return _ht.Insert(kv);
		}

		iterator begin()
		{
			return _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool > ret = _ht.Insert(make_pair(key,V()));
			return ret.first->secend;
		}

	};

	void test_ordered_map()
	{
		unordered_map<string,string> um;

		um.insert(make_pair("a", "a"));
		um.insert(make_pair("b", "b"));
		um.insert(make_pair("aa", "aa"));
		um.insert(make_pair("ab", "ab"));
		um.insert(make_pair("d", "d"));
		um.insert(make_pair("c", "c"));
		um.insert(make_pair("aaa", "aaa"));

		unordered_map<string,string>::iterator it = um.begin();
		while (it != um.end())
		{
			cout << it->first << ":" << it->second << endl;
			++it;
		}
		cout << endl;


	}
	

}